package ModelLayer;
import java.util.ArrayList;

public class ProductContainer
{
    public ArrayList<Product> productContainer;
    public static ProductContainer instance;
    public ProductContainer()
    {
       productContainer = new ArrayList<Product>();
    }
    public static ProductContainer getInstance()
    {
        if(instance == null)
        {
            instance = new ProductContainer();
        }
        return instance;
    }
    public void addProduct(Product product)
    {
        productContainer.add(product);
    }
    public Product findProduct(int productID)
    {
        int index = 0;
        boolean found = false;
        while(index < productContainer.size() && !found)
        {
            if(productContainer.get(index).getProductID() == productID)
            {
                found = true;
            }
            else
            {
                index++;
            }
        }
        return productContainer.get(index);
    }
    public boolean deleteProduct(int productID)
    {
        int index = 0;
        boolean found = false;
        while(index < productContainer.size() && !found)
        {
            if(productContainer.get(index).getProductID() == productID)
            {
                productContainer.remove(index);
                found = true;
            }
            else
            {
                index++;
            }
        }
        return found;
    }
    public Specimen getSpecimen(int productID, int serial)
    {        
        Specimen specimen = null;
        int index = 0;
        boolean found = false;
        while(index < productContainer.size() && !found)
        {
            if(productContainer.get(index).getProductID() == productID)
            {
                found = true;
                specimen = productContainer.get(index).getSpecimen(serial);
            }
            else
            {
                index++;
            }
        }
        return specimen;
    }
    public ArrayList<Product> listAllProducts()
    {
        return productContainer;
    }

   
}
